import { OpFaultProcessIM, OpFaultProcessPM, OpFaultProcessPPM, OpFaultProcessLRM } from '@/model/operations/faultprocess.model';
import { defHttp } from '@/utils/http/axios';
import { formatToDateTime } from '@/utils/core/DateUtil';
import dayjs from 'dayjs';

const basicApi = '/operations/admin/faultprocess';

enum Api {
  LIST = basicApi + '/list',
  GET = basicApi + '/',
  ADD = basicApi,
  EDIT = basicApi,
  EDIT_STATUS = basicApi + '/status',
  DEL_BATCH = basicApi + '/batch/',
  EXPORT = basicApi + '/export',
  DISPOSE = basicApi + '/dispose',
  DISPOSERESULT = basicApi + '/disposeResult',
  DISPOSECLOSE = basicApi + '/disposeClose',
}

/** 查询工单流程列表 */
export const listOpFaultProcessApi = (params?: OpFaultProcessPPM) =>
  defHttp.get<OpFaultProcessLRM>({ url: Api.LIST, params });

/** 查询工单流程详细 */
export const getOpFaultProcessApi = (id: string) =>
  defHttp.get<OpFaultProcessIM>({ url: Api.GET, params: id });

/** 新增工单流程 */
export const addOpFaultProcessApi = (params: OpFaultProcessIM) =>
  defHttp.post({ url: Api.ADD, params });

/** 修改工单流程 */
export const editOpFaultProcessApi = (params: OpFaultProcessIM) =>
  defHttp.put({ url: Api.EDIT, params });

/** 修改工单流程状态 */
export const editStatusOpFaultProcessApi = (id: string, status: string) =>
  defHttp.put({
    url: Api.EDIT_STATUS,
    params: { id: id, status: status },
  });

/** 删除工单流程 */
export const delOpFaultProcessApi = (ids: string | string[]) =>
  defHttp.delete({ url: Api.DEL_BATCH, params: ids.toString() });

/** 导出工单流程 */
export const exportOpFaultProcessApi = async (params?: OpFaultProcessPM) =>
  defHttp.export<any>(
    { url: Api.EXPORT, params: params },
    '工单流程_' + formatToDateTime(dayjs()) + '.xlsx',
  );

/** 流程受理 */
export const disposeOpFaultProcessApi = (params) =>
  defHttp.put({ url: Api.DISPOSE, params: params });

/** 流程处理结果 */
export const disposeResultOpFaultProcessApi = (params) =>
  defHttp.put({ url: Api.DISPOSERESULT, params: params });

/** 流程关闭 */
export const disposeCloseOpFaultProcessApi = (params) =>
  defHttp.put({ url: Api.DISPOSECLOSE, params: params });